<template>
  <BasicModal title="挂账支付 - 数据合并提交" @register="registerModal"
              :canFullscreen="false" :centered="true"
              :width="500" :height="260"
              :bodyStyle="{ padding:'0px' }"
              :cancelButtonProps="{ disabled: loading }"
              :okButtonProps="{ loading: loading }"
              @ok="handleSubmit"
  >
    <table id="businessAddFrom" cellpadding="0" cellspacing="1" class="formtable" style="font-size: 14px">
      <tr>
        <td align="right" width="80" height="30" class="enforcetd_bg"><label class="Validform_label"> 单位名称:</label></td>
        <td align="left" class="value">{{account.dwmc}}</td>
      </tr>
      <tr>
        <td align="right" width="80" height="30" lass="enforcetd_bg"><label class="Validform_label"> 收支类型:</label></td>
        <td align="left" class="value">{{account.sflxZW}}</td>
      </tr>
      <tr>
        <td align="right" width="80" height="30" class="enforcetd_bg"><label class="Validform_label"> 收支笔数:</label></td>
        <td align="left" class="value">{{account.counts}}</td>
      </tr>
      <tr>
        <td align="right" width="80" height="30" class="enforcetd_bg"><label class="Validform_label"> 付款金额:</label></td>
        <td align="left" class="value">{{account.je}}</td>
      </tr>
      <a-input type="hidden" id="business_id" name="business.id" v-model:value="account.businessId" />
      <a-input type="hidden" id="account_ids" name="account_ids" v-model:value="account.accountIds" />
      <a-input type="hidden" id="account_sflx" name="sflx" v-model:value="account.sflx" />
    </table>
  </BasicModal>
</template>
<script lang="ts" setup>
import "/@/design/tablefrom.css";
import { ref, computed, unref, onMounted, reactive } from "vue";
import { onPaymentInput, ajaxAccountOnTrustRefer } from "../types/accountflow.api";
import { BasicModal, useModalInner } from "/@/components/Modal";
import { object } from "vue-types";
import { useMessage } from "/@/hooks/web/useMessage";

const { createMessage: $message } = useMessage();
// 声明Emits
const emit = defineEmits(['success', 'register']);

let loading = ref<boolean>(false);
let account = reactive({accountIds: ''});

//表单赋值
const [registerModal, {setModalProps, closeModal}] = useModalInner(async (data) => {
  //重置表单
  //await resetFields();
  //setModalProps({confirmLoading: false});
  loading.value = false
  onPaymentInput({ids: data.ids}).then((res) => {
    Object.assign(account, res)
  })
});

//表单提交事件
async function handleSubmit() {
  try {
    //setModalProps({confirmLoading: true});
    loading.value = true
    ajaxAccountOnTrustRefer(account).then((res) => {
      //console.info("ajaxAccountOnTrustRefer@", res)
      loading.value = false
      if (res.success) {
        $message.success(res.message)
        emit("success")
        closeModal();
      } else {
        $message.error(res.message)
      }
    })
  } catch (e) {
    console.log(e);
  } finally {
    // setModalProps({confirmLoading: false});
  }
}

</script>
